<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="../include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
	<title>CRM-editdeal</title>
	<%@ include file="../include/head.jsp" %>
	
	<meta charset="UTF-8">
	<title></title>
</head>
<body class="crm">
	
	<jsp:include page="../include/top.jsp">
		<jsp:param value="deal" name="tag"/>
	</jsp:include>
	
		<div class="container-fluid">
		<div class="row-fluid">
			<div class="span8">
				<div class="well screen">
					<div class="page-header header">
					
						<table style="margin:0;">
							<tbody>
								<tr>
									<td width="68">
										<span style="display:inline-block;background: url(${basePath}/img/workxp_sprites.png) no-repeat scroll -224px -56px transparent; width: 55px; padding-top: 55px;"></span>
									</td>
									<td>
										编辑机会:${deal.title }
									</td>
								</tr>
							</tbody>
						</table>

					</div>
					
					<div class="live_search_spinner"  id="parties_loading">
						  <div class="liner">
					    <h3>处理中...</h3>
					    <img src="${basePath }/img/indicator.gif" alt="wait">
					  </div>
					</div>
					
					
					<div class="main" id="main">
						<div style="padding:0 68px;">
						
							<form accept-charset="UTF-8" action="update.action" class="simple_form form-vertical" id="deal_form" method="post" >
		
								<div class="control-group string optional  marco_polo_container">
									<label class="string optional control-label" for="chance_contact"> 联系人</label>
									<div class="controls">
										<input id="contact_id_deal"  type="hidden" name="deal.contact.id" value=${deal.contact.id }>
										<input class="input-xlarge mp_input" id="contact_name" name="deal.contact.name" type="text" value="${deal.contact.name }" >
											
											<ul class="typeahead dropdown-menu mp_list" style="top: 28px; left: 0px; display: none; ">
											</ul>
										
										<p class="help-block">输入联系人姓名或公司名称（并从下拉提示列表中选取一个）</p>
									</div>
								</div>
								
								<input id="deal_id" name="id" value="${deal.id }" type="hidden">
								<div class="control-group string required">
									<label class="string required control-label" for="deal_title">
										<abbr title="required">*</abbr> 
										机会名称
									</label>
									<div class="controls">
										<input class="string required input-xlarge" id="deal_title" name="deal.title" size="50" type="text" value="${deal.title }">
									</div>
								</div>
								<div class="control-group text optional">
									<label class="text optional control-label" for="deal_description"> 机会描述或背景信息</label>
									<div class="controls">
										<textarea class="text optional content" cols="40" id="deal_content" name="deal.content" rows="20">${deal.content }</textarea>
									</div>
								</div>
		
								<div class="control-group float optional">
									<label class="float optional control-label" for="deal_money"> 金额</label>
									<div class="controls">
										<div class="input-prepend">
											<span class="add-on">元</span>
											<input class="numeric float optional price" id="deal_money" name="deal.money" type="text" value="${deal.money }">
				
										</div>
									</div>
								</div>		
								<div class="control-group integer optional">
									<label class="integer optional control-label" for="dealtype_id"> 分类</label>
									<div class="controls">
										<input type="hidden" id="deal_dealtype_id" value="${deal.dealtype.id }">
										<select id="dealtype_id" name="dealtype.id" onchange="changeType(this)">
											<option value="">无</option>

											<c:forEach items="${dealtypeList }" var="dealtype">
												<option id="select" value="${dealtype.id }" >${dealtype.type }</option>	
											</c:forEach>
											
											<option value="new">新建分类 ...</option> 
										</select>
										<a href="${basePath }/dealtype/dealtype.action">编辑分类</a>
									</div>
								</div>		
								
								<script type="text/javascript">
									function changeType(a){
										if($(a).val()!="new")return;
										name=prompt("请输入新分类的名称:","");
										if(name != "") {
											$.post(
												"${basePath}/dealtype/newtype.action",
												{"dealtype.type":name},
												function(b){
													$(a).children(":first").before("<option selected='selected' value='" + b.typeid+ "'>" + b.type+ "</option>");
												});
											}
										}
								
								</script>
								
								<!-- <input id="chance_assigned_user_id" name="chance[assigned_user_id]" type="hidden" value="6641"> -->
			
								<div style="display:none" >
				
									<div id="select_access_policy_for_deal" class="select_access_policy">
											<div class="radio scope activated">
												<input checked="checked" id="chance_access_policy_attributes_scope_everyone" name="deal.view" type="radio" value="all"> 所有人
											</div>
											<div class="radio scope ">
												<input id="chance_access_policy_attributes_scope_owner" name="deal.view" type="radio" value="me"> 只有我能看见
												<input id="chance_access_policy_attributes_owner_id" name="user.id" type="hidden" value=${user.id }>
											</div>
											<div class="radio scope ">
												<input id="person_access_policy_attributes_scope_namedgroup" name="deal.view" type="radio" value="group"> 选择一个组...
												<div class="editor">
											  	<select class="named_group" id="person_access_policy_attributes_group_id" name="group.id">
											  		<option value="">选择一个组</option>
													<c:forEach items="${groupList }" var="group">
													
														<option  value="${group.id }">${group.groupname }</option>
														
													</c:forEach>
												</select> 
												</div>
											</div>
											<div class="radio scope">
												<input id="deal_access_policy_attributes_scope_adhocgroup" name="deal.view" type="radio" value="user"> 选择同事...
												<div class="editor">
												
										  		<select class="new_adhoc_group_member" id="deal_member" name="user.id">
										  			<option value="" selected="selected">选择一个同事...</option>
										  			<c:forEach items="${userList }" var="u">
														<option value="${u.id }">${u.username }</option>
										  			</c:forEach>	
												</select> 
												</div>
											</div>
							
									</div>

		<script>
			var container = $('#select_access_policy_for_deal');
			$('.scope input[type=radio]', container).live('click', function(event) {
		    var activated = $(event.target).parent();
		    $('.scope.activated', container).removeClass('activated');
		    activated.addClass('activated');
				
		  });
			
			$(document).ready(function(){
				var dealtypeid = $("#deal_dealtype_id").val();
				$("#dealtype_id option").each(function(i){
					if(dealtypeid == $(this).val()) {
						$("#select").attr("selected","selected");
					}
					//alert("第"+(i+1)+"个值为"+$(this).val());
				});
			});
			
		</script>
 
		</div>
	
	<div class="form-actions">
		<input class="btn btn-primary" name="commit"  type="button" id="btn" value="保存修改">
			<a href="show.action?id=${deal.id }" class="btn">取消</a>
		</div>
	</form>
	
</div>

<script type="text/javascript">
	$(document).ready(function(){
		$('#deal_title').focus();
		$("#btn").click(function(){
			var deal_name = $("#deal_title").val();
			if(deal_name.trim() != "") {
				$("#deal_form").submit();
			}
		});
	});
	
</script>

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$(document).ready(function() {
			$('#contact_name').marcoPolo({
			  url: 'contactListJson.action',
			  formatItem: function (data, $item) {
				    return data.name;
		      },
			  onSelect: function (data, $item) {
				
			  	$('#contact_name').val(data.name);
				$('#contact_id_deal').val(data.id);
			  	}
		      
			});
			
			
			validate_form('#chance_form');
			$('#chance_name').focus();
		});
	});
</script>

			</div>
		</div>
	</div>
		
		<div class="span4 sidebar">
			<div class="well">
				<div class="well">
					<i class="icon icon-trash"></i>
					<a href="delete.action?id=${deal.id }" data-confirm="您确定要删除这个机会吗？所有与这个机会相关的事件， 文件都将被删除。 
						删除后不能再恢复。" data-method="delete" rel="nofollow" title="删除这个机会">
						删除这个机会
					</a>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>
